package execxp

import (
	
	

	
)

func bothNodeOperator( tree.NodeSet,  tree.NodeSet,  *xpFilt,  string) error {
	var  error
	for ,  := range  {
		for ,  := range  {
			 := .ResValue()
			 := .ResValue()

			if eqOps[] {
				 = equalsOperator(tree.String(), tree.String(), , )
				if  == nil && .ctx.String() == tree.True {
					return nil
				}
			} else {
				 = numberOperator(tree.String(), tree.String(), , )
				if  == nil && .ctx.String() == tree.True {
					return nil
				}
			}
		}
	}

	.ctx = tree.Bool(false)

	return nil
}

func leftNodeOperator( tree.NodeSet,  tree.Result,  *xpFilt,  string) error {
	var  error
	for ,  := range  {
		 := .ResValue()

		if eqOps[] {
			 = equalsOperator(tree.String(), , , )
			if  == nil && .ctx.String() == tree.True {
				return nil
			}
		} else {
			 = numberOperator(tree.String(), , , )
			if  == nil && .ctx.String() == tree.True {
				return nil
			}
		}
	}

	.ctx = tree.Bool(false)

	return nil
}

func rightNodeOperator( tree.Result,  tree.NodeSet,  *xpFilt,  string) error {
	var  error
	for ,  := range  {
		 := .ResValue()

		if eqOps[] {
			 = equalsOperator(, tree.String(), , )
			if  == nil && .ctx.String() == "true" {
				return nil
			}
		} else {
			 = numberOperator(, tree.String(), , )
			if  == nil && .ctx.String() == "true" {
				return nil
			}
		}
	}

	.ctx = tree.Bool(false)

	return nil
}

func equalsOperator(,  tree.Result,  *xpFilt,  string) error {
	,  := .(tree.Bool)
	,  := .(tree.Bool)

	if  ||  {
		,  := .(tree.IsBool)
		,  := .(tree.IsBool)
		if ! || ! {
			return fmt.Errorf("Cannot convert argument to boolean")
		}

		if  == "=" {
			.ctx = tree.Bool(.Bool() == .Bool())
		} else {
			.ctx = tree.Bool(.Bool() != .Bool())
		}

		return nil
	}

	_,  = .(tree.Num)
	_,  = .(tree.Num)
	if  ||  {
		return numberOperator(, , , )
	}

	 := .String()
	 := .String()

	if  == "=" {
		.ctx = tree.Bool( == )
	} else {
		.ctx = tree.Bool( != )
	}

	return nil
}

func numberOperator(,  tree.Result,  *xpFilt,  string) error {
	,  := .(tree.IsNum)
	,  := .(tree.IsNum)
	if ! || ! {
		return fmt.Errorf("Cannot convert data type to number")
	}

	,  := .Num(), .Num()

	switch  {
	case "*":
		.ctx =  * 
	case "div":
		if  != 0 {
			.ctx =  / 
		} else {
			if  == 0 {
				.ctx = tree.Num(math.NaN())
			} else {
				if math.Signbit(float64()) == math.Signbit(float64()) {
					.ctx = tree.Num(math.Inf(1))
				} else {
					.ctx = tree.Num(math.Inf(-1))
				}
			}
		}
	case "mod":
		.ctx = tree.Num(int() % int())
	case "+":
		.ctx =  + 
	case "-":
		.ctx =  - 
	case "=":
		.ctx = tree.Bool( == )
	case "!=":
		.ctx = tree.Bool( != )
	case "<":
		.ctx = tree.Bool( < )
	case "<=":
		.ctx = tree.Bool( <= )
	case ">":
		.ctx = tree.Bool( > )
	case ">=":
		.ctx = tree.Bool( >= )
	}

	return nil
}

func andOrOperator(,  tree.Result,  *xpFilt,  string) error {
	,  := .(tree.IsBool)
	,  := .(tree.IsBool)

	if ! || ! {
		return fmt.Errorf("Cannot convert argument to boolean")
	}

	,  := .Bool(), .Bool()

	if  == "and" {
		.ctx =  && 
	} else {
		.ctx =  || 
	}

	return nil
}

func unionOperator(,  tree.Result,  *xpFilt,  string) error {
	,  := .(tree.NodeSet)
	,  := .(tree.NodeSet)

	if ! || ! {
		return fmt.Errorf("Cannot convert data type to node-set")
	}

	 := make(map[int]tree.Node)
	for ,  := range  {
		[.Pos()] = 
	}
	for ,  := range  {
		[.Pos()] = 
	}

	 := make(tree.NodeSet, 0, len())
	for ,  := range  {
		 = append(, )
	}

	.ctx = 

	return nil
}